//
//  KVNInfoItem.m
//  Test1
//
//  Created by KelvinYeung on 15/7/17.
//  Copyright (c) 2015年 KelvinYeung. All rights reserved.
//

#import "KVNInfoItem.h"

@interface KVNInfoItem() <UIGestureRecognizerDelegate>
@property UILabel *titleLabel;
@property UILabel *contentLabel;
@property UIImageView *imageView;

@end

@implementation KVNInfoItem
@synthesize titleLabel;
@synthesize contentLabel;
@synthesize imageView;
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype) init
{
    self = [super init];
    [self initSubViews];

    return self;
}

- (instancetype) initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    //[self initSubViews];
    return self;

}

- (void) initSubViews
{
    titleLabel = [[UILabel alloc] init];
    contentLabel = [[UILabel alloc] init];
    imageView = [[UIImageView alloc] init];
    
    
    contentLabel.textColor = [UIColor lightGrayColor];
    
    
    [self addSubview:titleLabel];
    [self addSubview:contentLabel];
    [self addSubview:imageView];
    
    //边框
    self.layer.borderWidth = 0.5;
    self.layer.borderColor = [[UIColor colorWithWhite:0.8 alpha:1] CGColor];
    
   
    //点击
    /*
    UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleFingerEvent:)];
    singleFingerOne.numberOfTouchesRequired = 1; //手指数
    singleFingerOne.numberOfTapsRequired = 1; //tap次数
    singleFingerOne.delegate = self;
    [self addGestureRecognizer:singleFingerOne];
    */
    //
    
}


- (void) drawRect:(CGRect)rect
{
    titleLabel.text = _title;
    contentLabel.text=_content;
    imageView.image = _image;
    
    //titleLabel.backgroundColor = [UIColor redColor];
    //contentLabel.backgroundColor = [UIColor whiteColor];
    imageView.backgroundColor = [UIColor lightGrayColor];
    
    float imageDiameter = rect.size.height * 0.60;
    
    imageView.frame = CGRectMake(10, rect.size.height *0.40*0.5, imageDiameter, imageDiameter);
    imageView.layer.masksToBounds = YES;
    imageView.layer.cornerRadius = imageDiameter * 0.5;
    
    titleLabel.frame = CGRectMake(rect.size.height *0.75 + 5, rect.size.height*0.15f, rect.size.width - 50 , 30);
    
    contentLabel.frame = CGRectMake(rect.size.height *0.75 + 5,rect.size.height*0.45f, rect.size.width - 50 , 30);
    [contentLabel setFont:[UIFont systemFontOfSize:12.0]];
    
    [super drawRect:rect];
    //[imageView drawRect:imageView.frame];
}




- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    self.backgroundColor=[UIColor lightTextColor];
    
}

- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
    self.backgroundColor=[UIColor whiteColor];
}

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    self.backgroundColor=[UIColor whiteColor];
}

@end
